package com.youi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.DelStatus;
import com.youi.dao.UseraddressDao;
import com.youi.entity.User;
import com.youi.entity.Useraddress;
import com.youi.service.UseraddressService;

@Service
public class UseraddressServiceImpl extends BaseServiceImpl<Useraddress> implements UseraddressService{
		
		private UseraddressDao useraddressDao;
		
		@Autowired
		public void setfaultRecordDao(UseraddressDao useraddressDao){
			this.useraddressDao=useraddressDao;
			super.setBaseDAO(useraddressDao);
		}
		
		@Override
		public void setDefultsAddress(Useraddress useraddress, User user) {
			// TODO Auto-generated method stub
			Map<String, Object> params = new HashMap<String, Object>();						
			params.put("id", useraddress.getId());			
			Map<String, Object> keyword = new HashMap<String, Object>();	
			keyword.put("userId", user.getId());
			keyword.put("delStatus", DelStatus.NODEL);
			List<Useraddress> useraddresseList=useraddressDao.getNotParamsList(params,keyword,null);	
			if (useraddresseList!=null&&useraddresseList.size()>0) {
				for (Useraddress address : useraddresseList) {
					address.setDefaults(0);
				}
				useraddressDao.saveOrUpdateAll(useraddresseList);
			}
		}
}